<?php
include 'includes/application_top.inc';
include 'includes/paginate.php';
include 'auth.php';
 $pagesUrl = "tpages=".@$_REQUEST['tpages']."&page=".@$_REQUEST['page'];
 
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Easy Living - Responsive Real Estate Template">
<meta name="keywords" content="Themes, real estate, responsive, themeforest, Templates">
<meta name="author" content="Rype Pixel [Chris Gipple]">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome News Nation Video Page</title>

<!-- html5 support in IE8 and later -->
<!--<script src="../../html5shiv.googlecode.com/svn/trunk/html5.js"></script>-->
<!-- CSS file links -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/responsive.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<!-- Start Header -->
<?php include 'includes/header.php';?>
<!-- End Header -->
<!-- start subheader -->
<p>&nbsp;</p>
<!-- start recent properties -->
<section class="properties">
    <div class="container">
    	<?php include 'includes/left.php';?>
        <div class="row">
            <div class="col-sm-6">
                <div class="propertyItem">
                	<!--  onsubmit="validate();"-->                	
                		<a href="<?php echo ROOTURL."listing_grid.php?".$pagesUrl;?>">Back</a>	
                		<?php
                		$RequestUrl="ac=DETAILS&tpages=".$_REQUEST['tpages']."&page=".$_REQUEST['page']."&id=".$_REQUEST['id']."";
						
						//if(@$_REQUEST['datepickerstart']!="" && @$_REQUEST['datepickerstart']!="")
                		?>
                		 <form action="listing_grid_details.php?<?php echo $RequestUrl;?>" method="post">
                		<table border="1" class="propertyDetails">
                			<tr class="tabHead">
                				<td>Search</td>
                                <td>Start Date:  <input type="text" id="datepickerstart" name="datepickerstart" value="<?php echo @$_REQUEST['datepickerstart'];?>"></td>
                                <td>End Date:  <input type="text" id="datepickerend" name="datepickerend" value="<?php echo @$_REQUEST['datepickerstart'];?>"></td>
                                <td><input type="submit" name="search" value="Search"><a href="<?php echo ROOTURL."listing_grid_details.php?".$RequestUrl;?>">Clear All</a></td>
                			</tr>
                		</table>
                         </form>	
                    <table border="1" class="propertyDetails">
                       <tr class="tabHead">
                            <td>MSISDN</td>
                            <td>User</td>
                            <td>OS</td>
                            <td>Date <a href="listing_grid_details.php?order=DateASC&<?php echo $RequestUrl;?>">^</a><a href="listing_grid_details.php?order=DateDESC&<?php echo $RequestUrl;?>">V</a></td>
                            <td>Incoming Url</td>
                            <td>Outgoing Url</td>
                        </tr>
                    	<?php
                    	$ids = $_REQUEST['id'];
                    	$per_page = 20;  						
						//print_r($_REQUEST);						 
						
						$datepickerstart = date("Y-m-d H:i:s",strtotime(@$_REQUEST['datepickerstart']));
						$datepickerend = date("Y-m-d H:i:s",strtotime(@$_REQUEST['datepickerend']));
						
						//`track_url`.`datetime`
						if(@$_REQUEST['order']=="DateDESC")
						{
						$order = " datetime DESC";	
						}else if(@$_REQUEST['order']=="DateASC")
							{
						$order = " datetime  ASC";	
							}
							else
							{
							$order = " id DESC";
							}
						if(@$_REQUEST['datepickerstart']!="" && @$_REQUEST['datepickerstart']!="")
						{
	   $select = "SELECT * FROM track_url left join shorturl on shorturl.id=track_url.shorturl_id WHERE  (datetime BETWEEN '$datepickerstart' AND '$datepickerend') AND  shorturl.id=$ids ORDER BY $order";							
						}
						else
						{
      $select = "SELECT * FROM track_url left join shorturl on shorturl.id=track_url.shorturl_id where shorturl.id=$ids ORDER BY $order ";
						}	

						$result = mysql_query($select);
						$total_results = mysql_num_rows($result);
						
						$total_pages = ceil($total_results / $per_page);//total pages we going to have
						
						//-------------if page is setcheck------------------//
						if (isset($_GET['page'])) {
						    $show_page = $_GET['page'];             //it will telles the current page
						    if ($show_page > 0 && $show_page <= $total_pages) {
						        $start = ($show_page - 1) * $per_page;
						        $end = $start + $per_page;
						    } else {
						        // error - show first set of results
						        $start = 0;              
						        $end = $per_page;
						    }
						} else {
						    // if page isn't set, show first set of results
						    $start = 0;
						    $end = $per_page;
						}
						// display pagination
						$page = intval(@$_GET['page']);
						
						$tpages=$total_pages;
						if ($page <= 0)
						    $page = 1;
                    	
						  $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
						 
                    echo '<div class="pagination"><ul>';
					$curRequest = $_REQUEST['id'];
                    if ($total_pages > 1) {
                        echo pagination($reload, @$show_page, $total_pages,$curRequest);
                    }
                    echo "</ul></div>";
					
					for ($i = $start; $i < $end; $i++) {
                        // make sure that PHP doesn't try to show results that don't exist
                        if ($i == $total_results) {
                            break;
                        }
                       $id= mysql_result($result, $i, 'id');
					   $long_url  =mysql_result($result, $i, 'long_url');
					   $shorturl_code = ROOTURL. mysql_result($result, $i, 'shorturl_code');
					   $long_url  =mysql_result($result, $i, 'long_url');
					   $msisdn  =mysql_result($result, $i, 'msisdn');
					   $os  =mysql_result($result, $i, 'os');
                        // echo out the contents of each row into a table
                        echo '<tr class="propertyDetails1">';
                        echo '<td>' .$msisdn . '</td>';
						echo '<td>'.$_SESSION['first_name'].'</td>';
						echo '<td>' .$os . '</td>';
						 echo '<td>' . mysql_result($result, $i, 'datetime') . '</td>';
                        echo '<td><a target="_blank" href="'.$shorturl_code .'">' .$shorturl_code . '</a></td>';
                         echo '<td>' . $long_url. '</td>';                    
                        echo "</tr>";
                    }
					if($total_results==0)
					{
					echo '<tr class="propertyDetails1"><td colspan="6">No record found</td></tr>';	
					}  
					?>    
				    </table>                    
                    <div>&nbsp;                    	
                    	</div>
                     
				<hr />
                </div>
            </div>
        </div><!-- end row -->
    </div><!-- end container -->
</section>
<!-- end recent properties -->
<div class="bottomBar">
    <div class="container">
        <p>CopyRight @ News Nation</p>
    </div>
</div>
<!-- JavaScript file links -->
<!--<script src="js/jquery.js"></script>			 Jquery -->
<script src="js/bootstrap.min.js"></script>  <!-- bootstrap 3.0 -->
<script src="js/respond.js"></script>
<!-- Jquery datepicker Start-->
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- Jquery datepicker End-->
 <script>
$(function() {
$( "#datepickerstart" ).datepicker();
});
$(function() {
$( "#datepickerend" ).datepicker();
});
</script>
 

	<script type="text/javascript">
	function redirecttest (argument) {
	  <!--
   var retVal = confirm("Do you want to delete ?");
   if( retVal == true ){
//      alert("User wants to continue!");
      window.location="action.php?URE=DELETE&<?php echo $pagesUrl;?>&id="+argument;
	  return true;
   }else{
    //  alert("User does not want to continue!");
	  return false;
   }
//-->
	}

</script>

<script type="text/javascript">
    function validate() {
        var url = document.getElementById("url").value;
        var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
        if (pattern.test(url)) {
            alert("Url is valid");
            return true;
        }else
        {
        	alert("Url is not valid!");
            return false;

        } 
            
    }
</script>
</body>
</html>